//
//  RMMDateUpView.m
//  Romomo
//
//  Created by puman on 16/10/13.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMDateUpView.h"

@interface RMMDateUpView ()<UITextFieldDelegate>
@end
@implementation RMMDateUpView
{
    UIButton *_cancelBut;
    UILabel *_dateLabel;

}
- (void)dealloc{
    NS_REM(UIKeyboardWillHideNotification, nil);
    NS_REM(UIKeyboardWillShowNotification, nil);
}
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _view = [[UIView alloc] initWithFrame:self.bounds];
        _view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
        _view.alpha = 0.0;
        [self addSubview:_view];
        
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        button.frame = CGRectMake(0, 0, self.width, self.height - 260);
        BUTTON_S(button, cancelButClick);
        [_view addSubview:button];
        
        _backView = [[UIView alloc] initWithFrame:CGRectMake(0, self.height, self.width, 260)];
        _backView.backgroundColor = kWhiteColor;
        [self addSubview:_backView];
        
        UILabel *labelTS = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, _backView.width - 75, 44)];
        labelTS.textColor = COLORFROMCODE(0x4A4A4A, 13);
        labelTS.font = kFont(13);
        labelTS.text = @"无法预约";
        [_backView addSubview:labelTS];
        
        _cancelBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _cancelBut.frame = CGRectMake(kScreenWideth - 60, 0, kHalf + kRow,44);
        [_cancelBut setTitleColor:COLORFROMCODE(0x9B9B9B, 1) forState:(UIControlStateNormal)];
        _cancelBut.titleLabel.font = kBFont(13);
        BUTTON_S(_cancelBut, cancelButClick);
        [_cancelBut setTitle:@"取消" forState:(UIControlStateNormal)];
        [_backView addSubview:_cancelBut];

        UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, labelTS.bottom, _backView.width, 0.5)];
        lineLabel.backgroundColor = RGBA(221, 221, 221, 1);
        [_backView addSubview:lineLabel];
        
        _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, lineLabel.bottom, 2 * kHalf + kMaric, 54)];
        _dateLabel.textColor = COLORFROMCODE(0x2C2C2C, 1);
        _dateLabel.font = kFont(18);
        _dateLabel.text = @"8月6日 20:30";
        [_backView addSubview:_dateLabel];
        
        UILabel *bookingLabel = [[UILabel alloc] initWithFrame:CGRectMake(_dateLabel.right, lineLabel.bottom + 18, kHalf + kRow, 18)];
        bookingLabel.textColor = kWhiteColor;
        bookingLabel.font = kFont(12);
        bookingLabel.backgroundColor = COLORFROMCODE(0xF95B45 , 1);
        bookingLabel.text = @"无法预约";
        bookingLabel.textAlignment = NSTextAlignmentCenter;
        bookingLabel.layer.masksToBounds = YES;
        bookingLabel.layer.cornerRadius = 3;
        [_backView addSubview:bookingLabel];
        
        UILabel *lineLabels = [[UILabel alloc] initWithFrame:CGRectMake(0, _dateLabel.bottom, _backView.width, 0.5)];
        lineLabels.backgroundColor = RGBA(221, 221, 221, 1);
        [_backView addSubview:lineLabels];
        
        UILabel *mobileLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, lineLabels.bottom, 55, kHalf + kRow)];
        mobileLabel.textColor = COLORFROMCODE(0x2C2C2C, 13);
        mobileLabel.font = kFont(13);
        mobileLabel.text = @"手机号码";
        [_backView addSubview:mobileLabel];
        
        _mobileT = [[UITextField alloc] initWithFrame:CGRectMake(mobileLabel.right + 15, lineLabels.bottom + kRow, kScreenWideth - 30 - mobileLabel.right, 2 * kMaric)];
        _mobileT.placeholder = @"请输入您的手机号码";
        _mobileT.backgroundColor = RGBA(238, 238, 238, 1);
        _mobileT.textColor = COLORFROMCODE(0xBFBFBF, 1);
        _mobileT.font = kFont(14);
        _mobileT.delegate = self;
        _mobileT.keyboardType = UIKeyboardTypeNumberPad;
        _mobileT.borderStyle = UITextBorderStyleRoundedRect;
        [_backView addSubview:_mobileT];
        
        UILabel *contextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, mobileLabel.bottom , kScreenWideth - 30, 40)];
        contextLabel.text = @"注: 我们会记录您的基本信息.待该时间可服务时, 客服将第一时间联系您。若没有剩余时间,容么么将不做另行通知。";
        contextLabel.font = kFont(13);
        contextLabel.numberOfLines = 0;
        contextLabel.textColor = COLORFROMCODE(0xBFBFBF, 1);
        [_backView addSubview:contextLabel];
       
        UILabel *lineLabelB = [[UILabel alloc] initWithFrame:CGRectMake(0, _backView.height - 49, _backView.width, 0.5)];
        lineLabelB.backgroundColor = RGBA(221, 221, 221, 1);
        [_backView addSubview:lineLabelB];
        
        _upButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _upButton.frame = CGRectMake(0, _backView.height - 48.5, kScreenWideth, 48.5);
        [_upButton setTitleColor:COLORFROMCODE(0x4A4A4A, 18) forState:(UIControlStateNormal)];
        _upButton.titleLabel.font = kBFont(18);
        _upButton.layer.cornerRadius = 18;
        [_upButton setTitle:@"提交" forState:(UIControlStateNormal)];
        [_backView addSubview:_upButton];
        
        UIView *gView = [[UIView alloc] initWithFrame:CGRectMake(0, contextLabel.bottom + kRow, self.width, _backView.height - 49 - contextLabel.bottom - kRow)];
        gView.backgroundColor = RGBA(243, 242, 243, 1);
        [_backView addSubview:gView];

        NS_ADD(keyShow:, UIKeyboardWillShowNotification, nil);
        NS_ADD(keyHide, UIKeyboardWillHideNotification, nil);
        
    }
    return self;
}
- (void)keyShow:(NSNotification *)fication{
    NSDictionary *userInfo = [fication userInfo];
    CGFloat keyHeight = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size.height;
    [UIView animateWithDuration:kInterval animations:^{
        _backView.frame = CGRectMake(0, self.height - keyHeight - 260, self.width, 260);
    } completion:^(BOOL finished) {
        
    }];

}
- (void)keyHide{
    [UIView animateWithDuration:kInterval animations:^{
        _backView.frame = CGRectMake(0, self.height, kScreenWideth, 260);
        _view.alpha = 0.0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}
- (void)cancelButClick{
    [_mobileT resignFirstResponder];
    [UIView animateWithDuration:kInterval animations:^{
        _backView.frame = CGRectMake(0, self.height, kScreenWideth, 260);
        _view.alpha = 0.0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
